package com.shangcheng.server.interceptor;


import com.shangcheng.model.domain.Admin;

/**
 * 工具类：实现向threadlocal存储数据的方法
 */
public class UserHolder {

    private static ThreadLocal<Admin> tl = new ThreadLocal<>();


    //将用户对象，存入Threadlocal
    public static void set(Admin admin) {
        tl.set(admin);
    }

    //从当前线程，获取用户对象
    public static Admin get() {
        return tl.get();
    }

    //从当前线程，获取用户对象的id
    public static Long getUserId() {
        return tl.get().getId();
    }

    //获取当前用户名
    public static String getUserName(){
        return tl.get().getUsername();
    }
    //清空数据
    public static void remove() {
        tl.remove();
    }
}
